//区县总体人数和金额
var myChart1 = echarts.init(document.getElementById('map1-a'));

var xAxis_leftTop = [];
var data1_leftTop = [];
var data2_leftTop = [];
var Xindex = 0;
var Arr_leftTop,Obj_leftTop;
var percent='',setline=13,setSize_leftTop=12,symbolAll=4,yAxisSize=16;
//开始
startLeftTop();
function startLeftTop(){
    $.ajax({
        type: "POST",
        url: baseurl+"city/listtotal",
        dataType: "json",
        success: function (data) {
            // console.log(data);
            myChart1.showLoading({
            text : "",
            maskColor:"rgba(53, 192, 255, 0)",
            });
            Arr_leftTop = data; //要操作的数组
            Obj_leftTop = []; //新的数组
            xAxis_leftTop =[];
            data1_leftTop=[];
            data2_leftTop=[];
            $.each(Arr_leftTop,function(i,n){
                xAxis_leftTop.push(n.county);
            })
            xAxis_leftTop = [...new Set(xAxis_leftTop)]; //将区域归纳整理好
            // console.log(xAxis_leftTop); 
            // xAxisLeftTop=xAxis_leftTop;
            xAxis_leftTop.forEach(function (el, index) { 
            // Obj_leftTop[el] = [];
            var moneyAll=0,peopleAll=0;
            // console.log(el)
            // xAxisLeftTop.push(el);
            Arr_leftTop.forEach(function (el1, index1) {
                if (el == el1.county) { //如果xAxis_leftTop [0] == Arr_leftTop.county 那么
                    moneyAll +=Number(el1.money);
                    peopleAll +=Number(el1.total_person);
                    
                // Obj[el].push(el1);
                }
            })
            Obj_leftTop.push({
                name: el,
                money: moneyAll,
                people:peopleAll
                })
            })
            // console.log(Obj_leftTop)//整理每个区域金钱与人数
            $.each(Obj_leftTop,function(i,n){
            data1_leftTop.push((parseInt(n.people)/10000).toFixed(3))
            })
            $.each(Obj_leftTop,function(i,n){
            data2_leftTop.push((parseInt(n.money)/10000).toFixed(4))
            })
            percent=parseFloat(setline/xAxis_leftTop.length)*100;
            percent=parseInt(percent);
            myChart1.setOption({
                dataZoom: [
                    {
                    show:false,
                    type: 'inside',
                    start: 0,
                    end: percent,
                }
                ],
                xAxis:[{
                        data:xAxis_leftTop,
                        axisLabel:{
                            fontSize:setSize_leftTop,
                        },
                }],
                yAxis:[{
                    axisLabel:{
                        fontSize:yAxisSize
                    }
                }],
                series: [
                    {
                        name:'人数(万)',
                        type:'bar',
                        data:data1_leftTop
                    },
                    {
                        symbolSize:symbolAll,
                        name:'资金(万)',
                        type:'line',
                        yAxisIndex: 1,
                        data:data2_leftTop
                    }
                ]
            });
            myChart1.hideLoading();
        }
    });
}
//点击地区
function dataZone(ZoneClick){
    $.ajax({
        type: "POST",
        url: baseurl+"county/townshipList",
        data:ZoneClick,
        dataType:"json",
        contentType: "application/json",
        success: function (data) {
            // console.log(data);
            // console.log(data.length);
            percent=parseFloat(setline/data.length)*100;
            percent=parseInt(percent);
            // console.log(percent);
            Arr_leftTop = data; //要操作的数组
            Obj_leftTop = []; //新的数组
            xAxis_leftTop =[];
            data1_leftTop=[];
            data2_leftTop=[];
            $.each(Arr_leftTop,function(i,n){
                xAxis_leftTop.push(n.township);
            })
            xAxis_leftTop = [...new Set(xAxis_leftTop)]; //将区域归纳整理好
            // console.log(xAxis_leftTop); 
            xAxis_leftTop.forEach(function (el, index) { 
            // Obj_leftTop[el] = [];
            var moneyAll=0,peopleAll=0;
            // console.log(el)
            Arr_leftTop.forEach(function (el1, index1) {
                if (el == el1.township) { //如果xAxis_leftTop [0] == Arr_leftTop.county 那么
                    moneyAll +=Number(el1.total_capital);
                    peopleAll +=Number(el1.total_person);
                    
                // Obj[el].push(el1);
                }
            })
            Obj_leftTop.push({
                name: el,
                money: moneyAll,
                people:peopleAll
                })
            })
            // console.log(Obj_leftTop)//整理每个区域金钱与人数
            $.each(Obj_leftTop,function(i,n){
            data1_leftTop.push((parseInt(n.people)/10000).toFixed(3))
            })
            $.each(Obj_leftTop,function(i,n){
            data2_leftTop.push((parseInt(n.money)/10000).toFixed(4))
            })
            myChart1.setOption({
                dataZoom: [
                    {
                    show:false,
                    type: 'inside',
                    start: 0,
                    end: percent,
                }
                ],
                xAxis:[{
                        data:xAxis_leftTop,
                }],
                series: [
                    {
                        name:'人数(万)',
                        type:'bar',
                        data:data1_leftTop
                    },
                    {
                        name:'资金(万)',
                        type:'line',
                        yAxisIndex: 1,
                        data:data2_leftTop
                    }
                ]
            });
            myChart1.hideLoading();
        }
    });
}
//点击项目
function dataPro(ProClick){
    $.ajax({
        type: "POST",
        url: baseurl+"county/topTotalProjectList",
        data:ProClick,
        dataType:"json",
        contentType: "application/json",
        success: function (data) {
            // console.log(data);
            // console.log(data.length);
            percent=parseFloat(setline/data.length)*100;
            percent=parseInt(percent);
            // console.log(percent);
            Arr_leftTop = data; //要操作的数组
            Obj_leftTop = []; //新的数组
            xAxis_leftTop =[];
            data1_leftTop=[];
            data2_leftTop=[];
            $.each(Arr_leftTop,function(i,n){
                xAxis_leftTop.push(n.county);
            })
            xAxis_leftTop = [...new Set(xAxis_leftTop)]; //将区域归纳整理好
            // console.log(xAxis_leftTop); 
            xAxis_leftTop.forEach(function (el, index) { 
            // Obj_leftTop[el] = [];
            var moneyAll=0,peopleAll=0;
            // console.log(el)
            Arr_leftTop.forEach(function (el1, index1) {
                if (el == el1.county) { //如果xAxis_leftTop [0] == Arr_leftTop.county 那么
                    moneyAll +=Number(el1.total_capital);
                    peopleAll +=Number(el1.total_person);
                    
                // Obj[el].push(el1);
                }
            })
            Obj_leftTop.push({
                name: el,
                money: moneyAll,
                people:peopleAll
                })
            })
            // console.log(Obj_leftTop)//整理每个区域金钱与人数
            $.each(Obj_leftTop,function(i,n){
            data1_leftTop.push((parseInt(n.people)/10000).toFixed(3))
            })
            $.each(Obj_leftTop,function(i,n){
            data2_leftTop.push((parseInt(n.money)/10000).toFixed(4))
            })
            myChart1.setOption({
                dataZoom: [
                    {
                    show:false,
                    type: 'inside',
                    start: 0,
                    end: percent,
                }
                ],
                xAxis:[{
                        data:xAxis_leftTop,
                }],
                series: [
                    {
                        name:'人数(万)',
                        type:'bar',
                        data:data1_leftTop
                    },
                    {
                        name:'资金(万)',
                        type:'line',
                        yAxisIndex: 1,
                        data:data2_leftTop
                    }
                ]
            });
            myChart1.hideLoading();
        }
    });
}
var option1 = {
//  title: {
//      text: '{titlename|地区概况}',
//      textStyle: {
////          color: '#1da1f2',
////          fontSize: '10',
//          rich:{
//          	titlename:{
//          		width: '100%',
//          		fontSize: '12',
//          		color: '#00f7fe',
//          		padding:[25,0,0,30]
//          	}
//          }
//      }
//  },
        tooltip : {
            trigger: 'axis',
            axisPointer: {
                crossStyle: {
                    color: '#999'
                }
            },
            position:'left',
            formatter:(params) =>{
                // console.log(params);
                var span="<span style='display:inline-block;margin-right:5px;border-radius:10px;width:"+hoverSize+"px;height:"+hoverSize+"px;background-color:#14c8d4;'></span>"
                var span2="<span style='display:inline-block;margin-right:5px;border-radius:10px;width:"+hoverSize+"px;height:"+hoverSize+"px;background-color:#ffffff;'></span>"
                let data = "<div class='leftCenter_hover'>"+
                "<p>"+params[0].name+"</p>"+
                "<p>"+span+"人数(万):"+params[0].value + "</p>"+
                "<p>"+span2+"资金(万):"+ params[1].value+"元"+"</p>"+
                "</div>";
			   return data;
            }
                
    },
//  legend: 
//  {
//      left:"55%",
//      textStyle:{
//          color:"#fff",
//      },
//      data:['人数','资金']
//  },
    dataZoom: [
        {
        show:false,
        type: 'inside',
        start: 0,
        end: 100,
    }
    ],
    grid: {
        left: '12%',
        right: '5%',
        bottom: '5%',
//      top:'0',
        containLabel: true
    },
    xAxis: [
        {
            offset:5,
            splitLine: {
                show: false
            },
            type: 'category',
            data: [],
            nameTextStyle:{
                color:"#fff",
            },
            axisPointer: {
                type: 'shadow',
                alignWithLabel: true
            },
            axisLabel:{
            	show:true,
                interval : 0, 
                color:"#fff",
                fontSize:16,
                // formatter: function (value) {
                //     //x轴的文字改为竖版显示
                //     var str = value.split("");
                //     return str.join("\n");
                //     // return '{a|' + value + '}';
                //     },
            },
        }
    ],
    yAxis: [
        {
            splitLine: {
                show: false
            },
            type: 'value',
            // name: '人数(万人)',
            nameTextStyle:{
                color:"#fff"
            },
            min: 0,
            interval: 50,
            axisLabel: {
            	show:true,
                formatter: '{value}',
                color:"#fff",
                fontSize:16,
            }
        }
        ,
        {
            show:false,
            splitLine: {
                show: false
            },
            type: 'value',
            // name: '资金(千万)',
            nameTextStyle:{
                color:"#fff"
            },
            min: 0,
            interval: 5000,
            axisLabel: {
            	show:false,
                formatter: '{value}',
                color:"#fff"
            }
        }
    ],
    series: [
        {
            name:'人数(万)',
            type:'bar',
            barCategoryGap:'50%',
            barWidth: '25%',
            data:[],
            itemStyle:{
                normal:{
                    // color:'#35d4b8'
                    color: new echarts.graphic.LinearGradient(
                        0, 0, 0, 1,
                        [
                            {offset: 0, color: '#43eec6'},
                            {offset: 1, color: '#14c8d4'}
                        ]
                    )
                }
            }
        },
        {
            name:'资金(万)',
            type:'line',
            yAxisIndex: 1,
            symbolSize:symbolAll,
            data:[],
            //调整线的颜色，透明度
            itemStyle: {
                normal: {
                    color: "#fff",
                    lineStyle: {
                        color: "#e8380d",
                        width:3,
                        opacity:0.5
                    }
                },
            }
        }
    ]
}
 function functionTitle(dataCity){
     var titelName=dataCity.title;
     return titelName;
 }
myChart1.setOption(option1);